package com.atguigu.gmall.mq.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.common.service.RabbitService;
import com.atguigu.gmall.mq.config.DeadLetterConfig;
import com.atguigu.gmall.mq.config.DelayedConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 李旭
 * @create: 2021-09-11 14:14
 *
 *   发消息
 **/
@RestController
@RequestMapping("/mq")
public class SendMessageController {

    //RabbitMQ 客户端
    @Autowired
    /*private RabbitTemplate rabbitTemplate;*/
    private RabbitService rabbitService;
    //发消息
    @GetMapping("/sendMessage/{message}")
    public Result sendMessage(@PathVariable String message){
      /*  rabbitTemplate.convertAndSend(
                "exchange123","routingKey123456789",message);*/
        rabbitService.sendMessage("exchange123",
                "routingKey123",message);
        return Result.ok();
    }
    //发延迟消息 基于死信
    @GetMapping("/sendDeadLetterMessage/{message}")
    public Result sendDeadLetterMessage(@PathVariable String message){
        rabbitService.sendDeadLetterMessage(DeadLetterConfig.exchange_dead,
                DeadLetterConfig.routing_dead_1,message,8);
        return Result.ok();
    }
    //发延迟消息  基于插件的
    @GetMapping("/sendDelayedMessage/{message}")
    public Result sendDelayedMessage(@PathVariable String message){
        rabbitService.sendDelayedMessage(DelayedConfig.exchange_delay,
                DelayedConfig.routing_delay,message,9);
        return Result.ok();
    }
}
